package study.lambda;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import study.lambda.interfaces.ApplePredicate;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class Apple  {

    private int weight;
    private String color;


    public static List<Apple> filterApples(List<Apple> inventory, Predicate<Apple> p) {
//        List<Apple> result = new ArrayList<>();
//        for(Apple apple: inventory){
//            if(p.test(apple)){
//                result.add(apple);
//            }
//        }
//        return result;

        return inventory.stream().filter(p).collect(Collectors.toList());
    }
}


class AppleHeavyWeightPredicate implements ApplePredicate {
    public boolean test(Apple apple) {
        return apple.getWeight() > 150;
    }
}

class AppleGreenColorPredicate implements ApplePredicate {
    public boolean test(Apple apple) {
        return "green".equals(apple.getColor());
    }
}
